package com.handpay.nocardpay.baselibrary.bankmanager.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;
import com.handpay.nocardpay.baselibrary.bankmanager.view.IModifyBankView;
import com.handpay.nocardpay.baselibrary.bankmanager.view.ISubBankView;
import com.handpay.nocardpay.baselibrary.qualificationinfo.model.bean.BankList;
import com.handpay.nocardpay.baselibrary.qualificationinfo.model.bean.SubBankBean;
import com.handpay.nocardpay.baselibrary.qualificationinfo.model.impl.BankModelImpl;

import java.util.HashMap;

/**
 * Created by sxshi on 2017/8/15.
 */

public class BankInfoPresenterImpl implements IBasePresenter {
    private Context mContext;
    private IModifyBankView modifyBankView;
    private BankModelImpl bankModel;
    private ISubBankView subBankView;

    public void setModifyBankView(IModifyBankView modifyBankView) {
        this.modifyBankView = modifyBankView;
    }

    public void setiSubBankView(ISubBankView subBankView) {
        this.subBankView = subBankView;
    }

    public BankInfoPresenterImpl(Context mContext) {
        this.mContext = mContext;
        bankModel = new BankModelImpl(mContext);
    }

    /**
     * 获取开户行列表
     *
     * @param paramers
     * @param clzz
     * @param isShowLoading
     */
    public void queryBankList(HashMap<String, Object> paramers, Class<BankList> clzz, boolean isShowLoading) {
        if (modifyBankView != null) {
            if (isShowLoading) {
                modifyBankView.showProgress();
            }
        }
        bankModel.queryBankList(paramers, clzz, new IBaseModel.OnRequestFinishedListener<BankList>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (modifyBankView != null) {
                    modifyBankView.hideProgress();
                    modifyBankView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(BankList response) {
                if (modifyBankView != null) {
                    modifyBankView.hideProgress();
                    modifyBankView.showBankList(response);
                }
            }
        });
    }

    /**
     * 获取支行列表
     *
     * @param paramers
     * @param clzz
     * @param isShowLoading
     */
    public void querySubBankList(HashMap<String, Object> paramers, Class<SubBankBean> clzz, boolean isShowLoading) {
        if (subBankView != null) {
            if (isShowLoading) {
                subBankView.showProgress();
            }
        }
        bankModel.querySubBankList(paramers, clzz, new IBaseModel.OnRequestFinishedListener<SubBankBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (subBankView != null) {
                    subBankView.hideProgress();
                    subBankView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(SubBankBean response) {
                if (subBankView != null) {
                    subBankView.hideProgress();
                    subBankView.showSubBankList(response);
                }
            }
        });
    }

    @Override
    public void onDestory() {
        if (modifyBankView != null) {
            modifyBankView = null;
        }
        if (subBankView != null) {
            subBankView = null;
        }
    }
}
